package com.airlenet.dubbo.demo;

import com.airlenet.dubbo.demo.api.HelloApi;
import com.airlenet.dubbo.demo.api.TestApi;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.UUID;

@SpringBootApplication

public class DemoConsumerApplication implements ApplicationRunner {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    public static void main(String[] args) {
        SpringApplication.run(DemoConsumerApplication.class, args);
    }

    @DubboReference
    HelloApi helloApi;

    @DubboReference
    TestApi testApi;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        try {
            for (; ; ) {
                logger.info("reply: {}",helloApi.sayHello("I'm Consumer "));
                testApi.test();
                logger.info("reply: {}", helloApi.sayObject(new HelloApi.HelloRequest(UUID.randomUUID().toString(), "Consumer")));
                Thread.sleep(3000);
            }
        }catch (Exception e){
            logger.error("",e);
        }


    }

}
